package com.lagou.controller;

import com.lagou.pojo.Article;
import com.lagou.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.awt.print.Pageable;
import java.util.List;

@Controller
public class BlogController {

    @Autowired
    BlogService blogService;


    @RequestMapping("/toIndex")
    public String toIndex(Model model, @RequestParam(value = "page",defaultValue = "1") Integer indexPage) {
        //List<Article> articles = blogService.findAll();
        PageRequest pageable = PageRequest.of(indexPage-1,3);
        Page<Article> page = blogService.findPageAll(pageable);
        List<Article> articles = page.getContent();
        model.addAttribute("articles",articles);
        model.addAttribute("page",page);
        return  "client/index";

    }
}
